package main.java.com.amanda.suaFa.no1;

import edu.princeton.cs.algs4.Bag;
import edu.princeton.cs.algs4.In;
import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut;

import java.util.ArrayList;
import java.util.List;

/**
 * @author amanda
 * @Description 背包的典型用例
 */
public class Status {
    public static void main(String[] args) {
        Bag<Double> numbers = new Bag<Double>();
        int n = 0;
        while (!StdIn.isEmpty()) {
            numbers.add(StdIn.readDouble());
            System.out.println(n++);
        }
        int N = numbers.size();
        double sum = 0.0;
        for (double x : numbers) {
            sum += x;
        }
        double mean = sum / N;

        sum = 0.0;
        for (double x : numbers) {
            sum += (x-mean)*(x-mean);
        }
        double std = Math.sqrt(sum - (N-1));
        StdOut.printf("Mean: %.2f\n", mean);
        StdOut.printf("Std dev: %.2f\n", std);
    }
}
